package org.uniport.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.uniport.dao.IUserDAO;
import org.uniport.vo.User;

public class UserDAOImpl implements IUserDAO {	
	
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	ResultSet rs = null;
	public UserDAOImpl(Connection conn){
		this.conn = conn;
	}
	
	
	public boolean addUser(User user) throws Exception {
		boolean flag = false;
		String sql = "INSERT INTO user(email,f_name,l_name,d_birth,u_password,uni,major,pic_id) VALUES(?,?,?,?,?,?,?,?)";
		this.pstmt = this.conn.prepareStatement(sql);
		this.pstmt.setString(1, user.getEmail());
		this.pstmt.setString(2, user.getF_name());
		this.pstmt.setString(3, user.getL_name());
		this.pstmt.setDate(4, user.getD_birth());
		this.pstmt.setString(5, user.getU_password());
		this.pstmt.setString(6, user.getUni());
		this.pstmt.setString(7, user.getMajor());
		this.pstmt.setInt(8, user.getPic_id());
		if(pstmt.executeUpdate()!=0){
			flag = true;
		}
		this.pstmt.close();
		return flag;
	}

}
